<?php session_start();
define('HOST', 'localhost');
define('USER', 'inventory');
define('PASS', 'inventory1234');
define('DB', 'inventory');

$link = mysql_connect(HOST,USER,PASS);
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db(DB, $link);
if (!$db_selected) {
    die ('Can\'t use '.DB.' : ' . mysql_error());
}

function trim_value(&$value)
{ 
	$value = trim($value); 
}

function escape(&$s){
	$s = mysql_real_escape_string($s);
}

array_walk_recursive($_REQUEST,'trim_value');
array_walk_recursive($_REQUEST,'escape');

array_walk_recursive($_GET,'trim_value');
array_walk_recursive($_GET,'escape');

array_walk_recursive($_POST,'trim_value');
array_walk_recursive($_POST,'escape');

function generateCode($length = 6){
		if ($length <= 0)
			return false;
		$code = "";
		$chars = "ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789";
		srand((double)microtime() * 1000000);
		for ($i = 0; $i < $length; $i++)
			$code = $code . substr($chars, rand() % strlen($chars), 1);
		return $code;
}